package com.jdd.enterprise.api.controller.admin;


import com.jdd.enterprise.api.dto.ApiRequest;
import com.jdd.enterprise.api.vo.ApiResponse;

import com.jdd.enterprise.api.vo.DishCategoryVO;
import com.jdd.enterprise.domain.entity.DishCategory;
import com.jdd.enterprise.domain.service.CategoryService;
import io.lettuce.core.GeoArgs;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.handler.MappedInterceptor;

import javax.swing.*;
import java.sql.ClientInfoStatus;
import java.util.List;
import java.util.Map;

@RestController

@RequestMapping("category")
@CrossOrigin
public class CategoryController {

    @Autowired
    private CategoryService categoryService;
/*
         展示分类列表
 */

    @PostMapping("searchByName")
    public ApiResponse<List<DishCategoryVO>>  searchByName(@RequestBody ApiRequest<DishCategory> request){

        List<DishCategoryVO> dishCategoryVOS = categoryService.searchByName(request.getParam());


        return  ApiResponse.success(dishCategoryVOS);

    }

    @PostMapping("selectOneLevelCategories")
    public ApiResponse<List<DishCategory>> selectOneLevelCategories(){

        List<DishCategory> dishCategories = categoryService.selectOneLevelCategories();

        return ApiResponse.success(dishCategories);


    }



    //对分类排序

    @PostMapping("sorting")
    public void sorting(@RequestBody  Map<Integer,Integer> map){


        categoryService.sorting(map);

    }



    //批量添加分类

    @RequestMapping("addBatchCategoriesOne")

    public  void  addBatchCategoriesOne(@RequestBody ApiRequest<List<DishCategory>> request){

        categoryService.addBatchCategoriesOne(request.getParam());

    }



    @PostMapping("addBatchCategoriesTwo")
    public void addBatchCategoriesTwo(@RequestBody ApiRequest<List<DishCategory>> request){
        categoryService.addBatchCategoriesTwo(request.getParam());
    }


//新建一级分类
    @PostMapping("addCategoryLevelOne")
    public void addCategoryLevelOne(@RequestBody ApiRequest<DishCategory> request){

categoryService.addCategoryLevelOne(request.getParam());

    }



@PostMapping("ceshi")
    public  ApiResponse<List<DishCategory>>  ceshi(){

    List<DishCategory> list = categoryService.list();

return  ApiResponse.success(list);
}





/*
      创建一级分类
 */
    @PostMapping("createCategoryOne")
    public void createCategoryOne(@RequestBody ApiRequest<DishCategory> request){

        categoryService.createCategoryOne(request.getParam());


    }





/*
      创建二级分类
 */

    @PostMapping("createCategoryTwo")
    public void createCategoryTwo(@RequestBody ApiRequest<DishCategory> request){
        categoryService.createCategoryTwo(request.getParam());

    }










/*
删除分类
 */



@PostMapping("deleteOneCategory")


    public void deleteOneCategory(@RequestBody ApiRequest<DishCategory>  request){


    categoryService.deleteOneCategory(request.getParam());

}

    @PostMapping("editCategory")
    public void  editCategory(@RequestBody ApiRequest<DishCategory> request){

    categoryService.editCategory(request.getParam());

    }








}
